import pandas as pd

df = pd.read_csv('../static/data/info.csv')
df['house_type'] = df['house_type'].apply(lambda x: '无' if pd.isnull(x) else x)
df['area'] = df['area'].apply(lambda x: '无' if pd.isnull(x) else x)
df['area'] = df['area'].apply(lambda x: x[3:-1])
df['area'] = df['area'].apply(lambda x: '0' if x == '' else x)
df['main_price'] = df['main_price'].apply(lambda x: x.split('|')[0])
df['main_price'] = df['main_price'].apply(
    lambda x: (int(x.split('-')[0]) + int(x.split('-')[1])) / 2 if len(x.split('-')) == 2 else x).astype('float')
df['total_price'] = df['total_price'].apply(lambda x: '0' if pd.isnull(x) else x)
df['total_price'] = df['total_price'].apply(lambda x: x[2:-5])
df['total_price'] = df['total_price'].apply(lambda x: '0' if x == '' else x)
df['region'] = df['address'].apply(lambda x: x.split('|')[0] + '区')
df['type'] = df['type_status'].apply(lambda x: x.split('|')[0])
df['area_mean'] = df['area'].apply(lambda x: (int(x) if len(x.split('-')) == 1 else int(x.split('-')[0]) + int(
    x.split('-')[1])) / 2 if x != '0' else 0).astype('float')
df['total_price_mean'] = df['total_price'].apply(lambda x: (float(x) if len(x.split('-')) == 1 else float(
    x.split('-')[0]) + float(x.split('-')[1])) / 2 if x != '0' else 0).astype('float')
df.to_csv('../static/data/info_pre.csv', index=False)
